<?php
/*
 * 手机客户端 秀场展品列表接口
 * 传入参数 
 * 2013-12-011
 */
include "inc/public_header.php";
include "inc/MiniaturePro.class.php";
include "func/user.php";				//用户信息处理函数
include "func/pic.php";					//图片处理函数

$reJson = array();//构建返回值
 
$page			= $_REQUEST["page"]; 			//页数，第一页为0
$pagesize		= $_REQUEST["pagesize"];		//每页记录数
$cid	     	= $_REQUEST["cid"];				//学校id
$panelWidth		= $_REQUEST["panelWidth"];		//屏幕宽度
$hd_id			= $_REQUEST["hd_id"];			//活动主键
$showSF			= $_REQUEST["showSF"];			//是否返回过滤,排序信息,  1:返回; 0:不返回
$version		= $_REQUEST["ver"];			//版本主键


if($version>1.4){
			$name = "name";
			$value= "value";
			$child="child";
		} else{
$name = "parentName";
			$value=	"key";
			$child=	"clist";
		}	
if($version>=1.7){
	if($panelWidth<480){
		$imgWidth  = 50;
	}else if($panelWidth>=480 && $panelWidth<=600){
		$imgWidth = 100;
	}else {
		$imgWidth = 150;
	}
} else{
	if($panelWidth<480){
		$imgWidth  = 100;
	}else if($panelWidth>=480 && $panelWidth<=600){
		$imgWidth = 200;
	}else {
		$imgWidth = 300;
	}
}	
	 
if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 20; //默认每页200条
}

$reJson["success"] = "1";


//获取作品总数量
$sql ="select count(0) as ct
		from 
				new_weituo_zuopin a	
				left join new_weituo_person d on a.uid=d.uid
		where
				a.dr='0'
				and a.aflag='1'
		";
if($cid){
	$sql = $sql." and d.xuexiao_id='".$cid."' ";
}
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and a.hd_id='".$hd_id."' ";
}
$db->query($sql);
$db->next_record();
$reJson["count"] = $db->f("ct"); //设置作品总数量（不分页）

//作品信息列表
$sql ="select t1.id,t1.uid,t1.aname,t1.gz_count,t1.ll_count,t1.pl_count,t1.czln,t1.img_path,t1.img_id,t1.type_id,t1.zan_count
			  ,t2.mini_img_id,t2.mini_img_width,t2.mini_img_height,t2.mini_img_aname";
if(isset($hd_id) && $hd_id!=""){
$sql = $sql." FROM (select id,uid,aname,gz_count,ll_count,pl_count,czln,img_path,img_id,type_id,zan_count,ctime from new_weituo_zuopin where dr=0 and aflag=1 and hd_id='".$hd_id."') t1"; 
}else{
$sql = $sql." FROM (select id,uid,aname,gz_count,ll_count,pl_count,czln,img_path,img_id,type_id,zan_count,ctime from new_weituo_zuopin where dr=0 and aflag=1) t1"; 	
}
$sql = $sql." LEFT JOIN (select img_id,id as mini_img_id,awidth as mini_img_width,aheight as mini_img_height,aname as mini_img_aname from new_weituo_pic_size where awidth='".$imgWidth."' ) t2 on t1.img_id=t2.img_id";
if($cid){
$sql = $sql." LEFT JOIN new_weituo_person t3 on t1.uid=t3.uid where t3.xuexiao_id='".$cid."'";
}
$sql .= " group by t1.id  order by t1.ctime desc limit ".($page * $pagesize).",".$pagesize;

$db->query($sql);
$worksArr = array();
$miniature = new MiniaturePro();	//构建缩略图处理类

while($db->next_record()){
	//处理生成缩略图
	$imgInfos = pic_resize(
							 $miniature
							,$db->f("img_path")
							,$db->f("mini_img_aname")
							,$imgWidth
							,$db->f("img_id")
							,$db->f("mini_img_id")
							,$db->f("mini_img_width")
							,$db->f("mini_img_height"));
	if($imgInfos["success"]=="0"){
		//图片有问题，无法显示
		continue;
	}
	$worksArr[] = array(
		"title"=>$db->f("aname")							//作品标题
		,"worksid"=>$db->f("id")							//作品id
		,"imgurl"=>$imgInfos["mini_img_url"]				//图片
		,"authorid"=>$db->f("uid")							//作者id
		,"praise"=>$db->f("zan_count")						//赞
		,"imgWidth"=>(string)$imgInfos["mini_img_width"]	//图片宽度
		,"imgHeight"=>(string)$imgInfos["mini_img_height"]	//图片高度
	);
}
$reJson["list"]=$worksArr;

if($showSF && intval($showSF,10)==1){
if($hd_id !=2){
$filter 		= array();
//学院信息
$sql = "select 
			distinct b.xuexiao_id
			,c.aname
		from 
			new_weituo_zuopin a 
			left join new_weituo_person b on a.uid=b.uid 
			left join new_weituo_xuexiao c on b.xuexiao_id=c.id 
		where 
			a.dr='0' 
			and a.aflag='1' 
			and not b.xuexiao_id is null 
			and c.id!='11'
		"; 
$sql = $sql."order by b.xuexiao_id desc ";
$db->query($sql);
$xuexiaoArr = array();
$xuexiaoArr[] = array(
		"name"=>"全部"											//学院名称
		,"value"=>""										//学院id

	);
while($db->next_record()){
	$xuexiaoArr[] = array(
		"name"=>$db->f("aname")											//学院名称
		,"value"=>$db->f("xuexiao_id")										//学院id

	);
}
if(count($xuexiaoArr)>0){
		
$filter[] = array(
		(string)$name=>"学院"
		,(string)$value=>"cid"
		,(string)$child=>$xuexiaoArr
	);
}		
//放入学校信息
$reJson["filter"] = $filter;
}
}
echo json_encode($reJson);
?>